<?php
// Module Body

function  dnsmail_domain_create(&$data) {
	global $cfg, $restartdns;

	// Get the config file
	if ($data['type'] == 'subdomain') {
		$data2 = fetchdata("*","domain",$data['owner']);
		$data['nohost'] = $data2['nohost'];
		$data['aliases'] = $data2['aliases'];
		$data['catchall'] = $data2['catchall'];
	}

	$dbp = mysql_query("SELECT max(ucount) AS ucount FROM domains WHERE domain='".$data['domain']."'");
	$ddata = mysql_fetch_array($dbp);

	/*	'DOMAIN'  => $data['domain'],
		'NS1'     => $cfg['dns_server1'],
		'NS2'     => $cfg['dns_server2'],
		'NS3'     => $cfg['dns_server3'],
		'NS4'     => $cfg['dns_server4'],
		'SERVER'  => $cfg['sysname'],
		'IP'      => $data['ip'], */


	// Send Mail

}

function dnsmail_domain_update(&$data) {
	global $cfg;

	// Compare old and newly generated named config file, write if necessary
		$namedinclude = $cfg['basedir']."/named/include/".$data['domain1'].".named";
		if (file_exists($namedinclude)) {
			$oldconf = file_get_contents($namedinclude);
		} else {
			$oldconf = " ";
		}

		if ($data['host'] != $data['host1'] OR $data['domain'] != $data['domain1'] OR crc32($oldconf) != crc32($namedconf)) {
			// if domain name changed, check if older file must be removed
			if ($data['domain'] != $data['domain1']) {
				$dbp = mysql_query("SELECT id FROM domains WHERE domain = '".$data['domain1']."'");
				if (!mysql_num_rows($dbp)) {
					$namedinclude = $cfg['basedir']."/named/include/".$data['domain1'].".named";
					if (file_exists($namedinclude))
						unlink($namedinclude);
				}
			}

                        // Send Mail

		}
}

function dnsmail_domain_remove(&$data) {
	global $cfg;

	// remove old config file only if this (old) domain is not used anymore.
	$dbp = mysql_query("SELECT id FROM domains WHERE domain='".$data['domain']."' AND action != 'remove'");
	if (!mysql_num_rows($dbp)) {
		$namedinclude = $cfg['basedir']."/named/include/".$data['domain'].".named";
		if (file_exists($namedinclude))
			unlink($namedinclude);
	}
	else {
                // Send Mail
	}
}

function  dnsmail_template(&$ret) {
	global $cfg;

	$template['title'] = 'DNS Mail';
	$template['servicename'] = 'dnsmail';
	$template['active'] = true;
	$template['file'][] = array('filename' => 'domain');
	$template['file'][] = array('filename' => 'reverse');

	$ret[] = $template;

}

function dnsmail_add_lang(&$data) {
	global $T;
	switch($data['lang']) {
		default:
			$T['dnsmail service'] = 'DNS Mail Service';
			break;
	}
}

function dnsmail_add_cfg(&$cfg) {
	$cfg['dnsmail'] = true;
	$cfg['dnsmail_reciptiant'] = "";
        $cfg['dnsmail_sender'] = "webcp@".$cfg['sysname'];
}
?>